<template>
<div class="text">
  <a-drawer
    title="编辑博士分数线管理"
    :width="windowWidth"
    placement="right"
    :closable="false"
    @close="onClose"
    :visible="departmentsEditVisiable"
    style="height: calc(100% - 55px);max-width:100%;overflow: auto;padding-bottom: 53px;"
  >
    <a-form>
      <a-form-item label="领域" v-bind="formItemLayout">
        <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="postParams.xkm" v-decorator="['xkm']" @change="xkChange">
          <a-select-option v-for="i in selectMenu.xk" :key="i.id" :value="i.xkdm">{{ i.xkmc }}</a-select-option>
        </a-select>
      </a-form-item>
       <a-form-item label="专业" v-bind="formItemLayout">
        <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="postParams.xkzym" v-decorator="['xkzym']">
          <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.xkdm">{{ i.xkmc }}</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="招生年度" v-bind="formItemLayout">
        <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="postParams.zsnj" v-decorator="['zsnj']">
          <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="外语听力" v-bind="formItemLayout">
        <a-input v-decorator="[
                  'wytlfsx',
                  {
                    rules: [{ required: true, message: '请输入外语听力!' }],
                  }
                ]" v-model="postParams.wytlfsx"/>
      </a-form-item>
      <a-form-item label="外语笔试" v-bind="formItemLayout">
        <a-input v-decorator="[
                  'wybsfsx',
                  {
                    rules: [{ required: true, message: '请输入外语笔试!' }],
                  }
                ]" v-model="postParams.wybsfsx"/>
      </a-form-item>
       <a-form-item label="外语口语" v-bind="formItemLayout">
        <a-input v-decorator="[
                  'wykyfsx',
                  {
                    rules: [{ required: true, message: '请输入外语口语!' }],
                  }
                ]" v-model="postParams.wykyfsx"/>
      </a-form-item>
       <a-form-item label="外语总分" v-bind="formItemLayout">
        <a-input v-decorator="[
                  'wyzffsx',
                  {
                    rules: [{ required: true, message: '请输入外语总分!' }],
                  }
                ]" v-model="postParams.wyzffsx"/>
      </a-form-item>
      <a-form-item label="业务课一" v-bind="formItemLayout">
        <a-input v-decorator="[
                  'ywkyfsx',
                  {
                    rules: [{ required: true, message: '请输入业务课一!' }],
                  }
                ]" v-model="postParams.ywkyfsx"/>
      </a-form-item>
       <a-form-item label="业务课二" v-bind="formItemLayout">
        <a-input v-decorator="[
                  'ywkefsx',
                  {
                    rules: [{ required: true, message: '请输入业务课二!' }],
                  }
                ]" v-model="postParams.ywkefsx"/>
      </a-form-item>
      <a-form-item label="业务课三" v-bind="formItemLayout">
        <a-input v-decorator="[
                  'ywksfsx',
                  {
                    rules: [{ required: true, message: '请输入业务课三!' }],
                  }
                ]" v-model="postParams.ywksfsx"/>
      </a-form-item>
      <a-form-item label="业务课总分" v-bind="formItemLayout">
        <a-input v-decorator="[
                  'ywkzcjfsx',
                  {
                    rules: [{ required: true, message: '请输入业务课总成绩!' }],
                  }
                ]" v-model="postParams.ywkzcjfsx"/>
      </a-form-item>
      
    </a-form>
    <div class="drawer-bootom-button">
      <a-button style="margin-right: .8rem" @click="onClose">取消</a-button>
      <a-button @click="handleSubmit" type="primary" :loading="loading">保存</a-button>
    </div>
  </a-drawer>
  </div>
</template>

<script>
// import moment from 'moment'
import { STable } from "~";
import { mapState } from "vuex";

const formItemLayout = {
  labelCol: { span: 3 },
  wrapperCol: { span: 18 }
};

const selectArr = ["TYPE0126", "TYPE0075", "TYPE0125", "TYPE0072"];
export default {
  name: "DepartmentsEdit",
  props: {
    info: {
      default: () => ({
        xkmlm: "",
        xkm: "",
        xkzym: "",
        wytlfsx:"",
        wybsfsx:"",
        wykyfsx:"",
        wyzffsx:"",
        ywkyfsx:"",
        ywkefsx:"",
        ywksfsx:"",
        ywkzcjfsx:"",
        id:""
        
      })
    },
    departmentsEditVisiable: {
      default: false
    }
  },
  components: {
    STable
  },
  data() {
    return {
      formItemLayout,
      loading: false,
      data: [],
      postParams: {
        xkmlm: "",
        xkm: "",
        xkzym:'',
        zsnj: "",
        wytlfsx:"",
        wybsfsx:"",
        wykyfsx:"",
        wyzffsx:"",
        ywkyfsx:"",
        ywkefsx:"",
        ywksfsx:"",
        ywkzcjfsx:"",
        id:""
      },
      winWidth:"650",
      windowWidth:"650",
      // 表头
      columns: [
        {
          title: "",
          dataIndex: "column"
        },
        {
          title: "计划",
          scopedSlots: { customRender: "plan" }
        },
        {
          title: "已分配",
          dataIndex: "distribution"
        }
      ],
      selectMenu: {
        ml: [], // 门类
        xk: [],
        zy: []
      }
    };
  },
  beforeCreate(){
      this.form = this.$form.createForm(this)
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app["TYPE0126"] // 年级
    })
  },
  watch: {
    winWidth(val){
      let that=this
      setTimeout(function(){
      if(val<650){
      that.windowWidth =val
      }else{
        that.windowWidth="650"
      }
      },400)
    },
    info(val) {
       this.initSelectMenu();
      // console.log(val)
      if(val.xkmlm){
      this.getProsessionList(val.xkmlm)
      }
      if(val.xkm){
       this.getXkChangeList(val.xkm);
      }
      
    //   this.form.setFieldsValue({'xkmlm':val.xkmlm})
      this.postParams = {
        xkmlm: val.xkmlm,
        zsnj: val.zsnj,
        xkm: val.xkm,
        xkzym:val.xkzym,
        wytlfsx:val.wytlfsx,
        wybsfsx:val.wybsfsx,
        wykyfsx:val.wykyfsx,
        wyzffsx:val.wyzffsx,
        ywkyfsx:val.ywkyfsx,
        ywkefsx:val.ywkefsx,
        ywksfsx:val.ywksfsx,
        ywkzcjfsx:val.ywkzcjfsx,
        id:val.id
      };
      this.data = [
        {
          column: "总计划",
          plan: val.zszjhrs,
          distribution: 1,
          key: "zszjhrs"
        },
        {
          column: "非专业学位计划",
          plan: val.fzyxwjhrs,
          distribution: 1,
          key: "fzyxwjhrs"
        },
        {
          column: "专业学位计划",
          plan: val.zyxwjhrs,
          distribution: 1,
          key: "zyxwjhrs"
        }
      ];
    }
  },
  mounted(){
    //监听屏幕宽度,放入winWidth
    const that=this
    that.windowWidth = document.body.clientWidth>650?650:document.body.clientWidth
    window.onresize=()=>{
      return (()=>{
        window.screenWidth=document.body.clientWidth
        that.winWidth=window.screenWidth
      })()
    }
  },
  created() {
   
    selectArr.forEach(v => {
      this.$store.dispatch("app/setDictionary", v);
    });
  },
  methods: {
    initSelectMenu() {
      let code = "04";
      let parms = { xklb: code };
      let allRequest = [this.$api.base.subjectAll(parms)];
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          xk: res[0].data
        };
      });
      //    var ml = this.selectMenu.ml
      //   this.$api.base.subjectAll().then(res =>{
      //       if(res.data){
      //           this.selectMenu={
      //               xk:res.data
      //           }
      //       }
      //   })
    },
    mlChange(code) {
      console.log(code);
      this.postParams.xkm='';
      this.postParams.xkzym='';
      // this.form.setFieldsValue({'xkm':'','xkzym':''})
      this.getProsessionList(code)
    },
    getProsessionList(code) {
      this.$api.base
        .subjectAll({
          fjxkdm: code
        })
        .then(res => {
          if (res.data) {
          this.$set(this.selectMenu,'xk',res.data)
          }
        });
    },
    xkChange(code){
      this.postParams.xkzym='';
      this.getXkChangeList(code);
    },
    getXkChangeList(code){
        this.$api.base.linkageMajor({
                 xkdm: code
                 }).then(res => {
                            if (res.data) {
                               this.$set(this.selectMenu,'zy',res.data)
                            }
                        })  
    },
    reset() {
      this.data = [
        {
          column: "总计划",
          plan: "",
          distribution: 1,
          key: "zjh"
        },
        {
          column: "非专业学位计划",
          plan: "",
          distribution: 1,
          key: "fzyxwjh"
        },
        {
          column: "专业学位计划",
          plan: "",
          distribution: 1,
          key: "zyxwjh"
        }
      ];
    },
    // 选择院系
    yxChange(code) {
      this.$set(this.queryParam, "sszym", "");
      this.$api.base.majorAll({ lsdwh: code }).then(res => {
        this.$set(this.selectMenu, "zy", res.data);
      });
    },
    // 选择招生年度
    zsndChange() {},
    // 关闭
    onClose() {
      this.reset();
      this.$emit("close");
    },
    // 保存
    handleSubmit() {
     
      // console.log(paramms)
      this.$api.doctorRecruit
        .fractionalUpdate(this.postParams)
        .then(res => {
           this.$message.success(res.msg)
          this.$emit("success");
        })
        .finally(() => {
          this.loadingBtn = false;
          // this.form.resetFields()
        });
    },
    // 修改各计划人数人数
    handleChange(key, dataIndex, value) {
      const dataSource = [...this.data];
      const target = dataSource.find(item => item.key === key);
      if (target) {
        target[dataIndex] = value;
        this.data = dataSource;
      }
    }
  }
};
</script>
<style lang="less" scoped>
      body /deep/ .ant-drawer-right.ant-drawer-open .ant-drawer-content-wrapper{
        width: 100% !important
      }
       body :global(.ant-drawer-right.ant-drawer-open .ant-drawer-content-wrapper){
        width: 100% !important
      }
</style>